<extend name="Public/base"/>

<block name="body">
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>{:isset($info['id'])?'编辑':'新增'}视频</h2>
    </div>
    <form action="{:U('edit')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">标题</label>
            <div class="controls">
                <input type="text" class="text input-large" name="title" value="{$info.title|default=''}">
            </div>
        </div>
        
        <div class="form-item">
            <label class="item-label">排序<span class="check-tips">（用于分组显示的顺序）</span></label>
            <div class="controls">
                <input type="text" class="text input-small" name="sort" value="{$info.sort|default=0}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">外链<span class="check-tips">（跳转另外链接）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="link" value="{$info.link|default=''}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">视频地址<span class="check-tips">（resources_link）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="resources_link" value="{$info.resources_link|default=''}">
            </div>
        </div>
        <div class="form-item">
	     	<label class="item-label">视频文件</label>
	     	<div class="controls">
	     		<input type="file" id="upload_movie">
	     		<div class="upload-img-box">
	     			<notempty name="info.movie">
	     				<input type="hidden" name="movie" value="{$info.movie}"/>
	     				<video id="myvideo" class="video-js vjs-big-play-centered" controls preload="auto" width="480" height="240" data-setup="{}">
	     					<source src="__ROOT__/Uploads/Movie/{$info.movie|get_movie='savepath'}{$info.movie|get_movie='savename'}" type='{$info.movie|get_movie='mime'}'>
	     				</video>
	     			</notempty>
	     		</div>
	     		<script type="text/javascript">
				//上传图片
			    /* 初始化上传插件 */
				$("#upload_movie").uploadify({
			        "height"          : 30,
			        "swf"             : "__STATIC__/uploadify/uploadify.swf",
			        "fileObjName"     : "download",
			        "buttonText"      : "上传视频文件",
			        "uploader"        : "{:U('File/uploadMovie',array('session_id'=>session_id()))}",
			        "width"           : 120,
			        'removeTimeout'	  : 1,
			        'multi'			  : false,
			        'fileTypeExts'	  : '*.flv; *.avi; *.wma; *.rmvb; *.rm; *.flash; *.mp4; *.mid; *.3gp;',
			        "onUploadSuccess" : uploadMovie,
			        'onFallback' : function() {
			            alert('未检测到兼容版本的Flash.');
			        }
			    });
				
				var curr_video = { id: '{$info.movie}', src: '__ROOT__/Uploads/Movie/{$info.movie|get_movie='savepath'}{$info.movie|get_movie='savename'}', type: '{$info.movie|get_movie='mime'}'};
				
				function uploadMovie(file, data){
			    	var data = $.parseJSON(data);
			        if(data.status){
			        	mime = data.info.mime;
			        	if (mime == undefined || mime == '') {
			        		mime = data.info.type;
			        	}
			        	curr_video.id = data.info.id, curr_video.src = '__ROOT__/Uploads/Movie/' + data.info.savepath + data.info.savename, curr_video.type = mime;
			        	preloadvideo();
			        } else {
			        	updateAlert(data.info);
			        	setTimeout(function(){
			                $('#top-alert').find('button').click();
			                $(that).removeClass('disabled').prop('disabled',false);
			            },1500);
			        }
			    }
				
				var row = 0;
				
				function preloadvideo() {
					if (curr_video.id == '' || curr_video.id == undefined) {
						return false;
					}
					
					$("#upload_movie").parent().find('.upload-img-box').html(
		        		'<input type="hidden" name="movie" value="' + curr_video.id + '"/><video id="myvideo' + row + '" class="video-js vjs-big-play-centered" controls preload="auto" width="480" height="240" data-setup="{}"><source src="' + curr_video.src + '" type="' + curr_video.type + '"></video>'
		        	);
					
					videojs('myvideo'+row).ready(function(){
		        		this.preload();
		        	});
					
					row++;
				}
				</script>
			</div>
		</div>
		<div class="form-item">
			<label class="item-label">视频缩略图<span class="check-tips"></span></label>

			<div class="controls">
				<input type="file" id="upload_picture_file">
				 <input type="hidden" name="thumb_cover_id" id="cover_id"  value="{$thumb_cover_id}" />
				<div class="upload-img-box">
					<notempty name="thumb_cover_id">
					<div class="upload-pre-item">					
						<img src="{$thumb_cover_id|get_cover='path'}" />					
						<span class="btn-close" title="删除图片" onclick="$(this).parent().remove();"></span>
					</div>
					</notempty>
				</div>
			</div>
			<script type="text/javascript">
								//上传图片
							    /* 初始化上传插件 */
								$("#upload_picture_file").uploadify({
							        "height"          : 30,
							        "swf"             : "__STATIC__/uploadify/uploadify.swf",
							        "fileObjName"     : "download",
							        "buttonText"      : "上传图片",
							        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
							        "width"           : 120,
							        'removeTimeout'	  : 1,
							        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
							        "onUploadSuccess" : uploadPicture_panel,
							        'onFallback' : function() {
							            alert('未检测到兼容版本的Flash.');
							        }
							    });
								function uploadPicture_panel(file, data){
							    	var data = $.parseJSON(data);
							    	var src = '';
							        if(data.status){
							        	$("#cover_id").val(data.id);
							        	src = data.url || '__ROOT__' + data.path
							        	$("#cover_id").parent().find('.upload-img-box').html(
							        		'<div class="upload-pre-item"><img src=" ' + src + '"/></div>'
							        	);
							        } else {
							        	updateAlert(data.info);
							        	setTimeout(function(){
							                $('#top-alert').find('button').click();
							                $(that).removeClass('disabled').prop('disabled',false);
							            },1500);
							        }
							    }
				</script>
		</div>
        <div class="form-item">
        	<label class="item-label">详细描述</label>
			<div class="controls">
				<label class="textarea">
					<textarea name="description">{$info.description}</textarea>
					{:hook('adminArticleEdit')}
				</label>
			</div>
		</div>
        <div class="form-item">
        	<input type="hidden" value="video" name="type" />
        	<input type="hidden" value="{$info.id}" name="id" />
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">

<link rel="stylesheet" type="text/css" href="__STATIC__/videojs/css/video-js-5.2.1.css" />
<script type="text/javascript" src="__STATIC__/videojs/js/video-js-5.2.1.js"></script>
<script type="text/javascript">
//导航高亮 
highlight_subnav('{:U('index')}');
</script>
</block>